/**
  ******************************************************************************
  * @file    gt32f030_adc.c
  * @author  GT Application Team
  * @version V1.0.0
  * @date    03-January-2025   
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; COPYRIGHT 2022 Giantec Semicondutor Inc</center></h2>
  *
  *             http://www.giantec-semi.com/
  *
  * Unless required by applicable law or agreed to in writing, software 
  * distributed under the License is distributed on an "AS IS" BASIS, 
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  *
  ******************************************************************************
  */

/* Includes ------------------------------------------------------------------*/
#include "gt32f030_rcc.h"
#include "gt32f030_adc.h"


/** @addtogroup GT32F030_StdPeriph_Driver
  * @{
  */

/** @defgroup ADC 
  * @brief 		ADC driver modules
  * @{
  */ 

/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/ 
#define ADC_CR0_BUFF       ((uint32_t)0x00000040)
#define ADC_CR0_JAUTO      ((uint32_t)0x00000020)
#define ADC_CR0_SCAN       ((uint32_t)0x00000010)
#define ADC_CR0_CONT       ((uint32_t)0x00000008)
#define ADC_CR0_DMA        ((uint32_t)0x00000002)
#define ADC_CR0_ON         ((uint32_t)0x00000001)


#define ADC_CR4_CLKPRESCALEMask     ((uint32_t)0x00ff0000)
#define ADC_CR4_POWERONDELAYMask    ((uint32_t)0x000003ff)
#define ADC_CR3_ACCLENGTHMask       ((uint32_t)0x00ff0000)
#define ADC_CR3_DISCNUMMask         ((uint32_t)0x00000007)
#define ADC_CR12_EXTTRGEDGEMask     ((uint32_t)0xC0000000)
#define ADC_CR12_EXTTRGSRCMask      ((uint32_t)0x0003f000)
#define ADC_SQR_SQRLENGTHMask       ((uint32_t)0xF0000000)
#define ADC_JSQR_JSQRLENGTHMask     ((uint32_t)0xC0000000)
#define ADC_CR12_SWSTART            ((uint32_t)0x00000800)
#define ADC_CR0_POWERON             ((uint32_t)0x00000001)
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/


/** @defgroup 	ADC_Private_Functions
  * @{
  */ 

/** @defgroup 	ADC_Init Initialization functions
 *  @brief    	Initialization functions 
 *
@verbatim    
 ===============================================================================
              ##### Initialization functions #####
 ===============================================================================
@endverbatim
  * @{
  */

/**
  * @brief  Deinitializes the ADC peripheral registers to their default reset 
  *         values.
  * @param  None
  * @retval None
  */
void ADC_DeInit(void)
{
	RCC_PeriphResetCmd(RCC_PeriphReset_ADC, ENABLE);
	RCC_PeriphResetCmd(RCC_PeriphReset_ADC, DISABLE);
}

/**
  * @brief  Initializes the ADC peripheral according to the specified parameters 
  *         in the ADC_InitStruct.
  * @param  ADC_InitStruct: pointer to an ADC_InitTypeDef structure that contains
  *         the configuration information.
  * @retval None
  */
void ADC_Init(ADC_InitTypeDef* ADC_InitStruct)
{
	unsigned int tp1;
  /* Check the parameters */
  assert_param(IS_ADC_VERF(ADC_InitStruct->ADC_VrefSel));  
  assert_param(IS_ADC_CLKPRESCALE(ADC_InitStruct->ADC_ClkPrescale));
  assert_param(IS_ADC_PWONDLY(ADC_InitStruct->ADC_PowerOnDelay));
  assert_param(IS_FUNCTIONAL_STATE(ADC_InitStruct->ADC_InputBuf));
		
	tp1  = ADC->CR0;
	tp1 &=~ ADC_CR0_BUFF;
	tp1 |= ((ADC_InitStruct->ADC_InputBuf&1)<<6);
	ADC->CR0 = tp1;
	
	tp1  = ADC->CR4;
	tp1 &=~ (ADC_CR4_CLKPRESCALEMask|ADC_CR4_POWERONDELAYMask);
	tp1 |=  ((ADC_InitStruct->ADC_ClkPrescale<<16)|ADC_InitStruct->ADC_PowerOnDelay);
	ADC->CR4 = tp1;
}	

/**
  * @brief  Fills each ADC_InitStruct member with its default value. 
  * @param  ADC_InitStruct: pointer to an ADC_InitTypeDef structure which will 
  *         be initialized.
  * @retval None
  */
void ADC_StructInit(ADC_InitTypeDef* ADC_InitStruct)
{
	/* ADC_InitStruct members default value */	
  ADC_InitStruct->ADC_ClkPrescale  = 3; 
  ADC_InitStruct->ADC_PowerOnDelay = 3; 
	ADC_InitStruct->ADC_InputBuf     = ENABLE; 
}

/**
  * @}
  */

/** @defgroup 	ADC_OpCfg Operation and Configuration functions
 *  @brief    	Operation and Configuration functions 
 *
@verbatim    
 ===============================================================================
              ##### Operation and Configuration functions #####
 ===============================================================================
@endverbatim
  * @{
  */
/**
  * @brief  Configures the Sample Channel according to the specified parameters 
  *         in the ADC_SampChnCfgStruct.
  * @param  ADC_SampChnCfgStruct: pointer to an ADC_SampChnCfgTypeDef structure 
  *         that contains the configuration information 
  * @retval None
  */
void ADC_SampChnConfig(ADC_SampChnCfgTypeDef* ADC_SampChnCfgStruct)
{
  unsigned int tp1,tp2;
	/* Check the parameters */
	assert_param(IS_ADC_CHNSRC(ADC_SampChnCfgStruct->ADC_SampChn));	
	assert_param(IS_ADC_SAMPCLK(ADC_SampChnCfgStruct->ADC_SampChnCycle));
	assert_param(IS_FUNCTIONAL_STATE(ADC_SampChnCfgStruct->ADC_SampChnAWD));
	assert_param(IS_FUNCTIONAL_STATE(ADC_SampChnCfgStruct->ADC_SampChnACCCmd));
	assert_param(IS_ADC_ACCLENGTH(ADC_SampChnCfgStruct->ADC_SampChnACCLength));
	
	if(ADC_SampChnCfgStruct->ADC_SampChn<=5)
	{
	  tp1=ADC->SMPR2;
		tp1 &=~(0x1f<<(ADC_SampChnCfgStruct->ADC_SampChn*5));
		tp2  = ADC_SampChnCfgStruct->ADC_SampChnCycle        |
		       ((ADC_SampChnCfgStruct->ADC_SampChnAWD&1)<<3) |
		       ((ADC_SampChnCfgStruct->ADC_SampChnACCCmd&1)<<4);
		tp2 <<= (ADC_SampChnCfgStruct->ADC_SampChn)*5;
		ADC->SMPR2 = tp1|tp2;
	}
	else
	{
	  tp1=ADC->SMPR1;
		tp1 &=~(0x1f<<((ADC_SampChnCfgStruct->ADC_SampChn-6)*5));
		tp2 = ADC_SampChnCfgStruct->ADC_SampChnCycle        |
		      ((ADC_SampChnCfgStruct->ADC_SampChnAWD&1)<<3) |
		      ((ADC_SampChnCfgStruct->ADC_SampChnACCCmd&1)<<4);
		tp2 <<= ((ADC_SampChnCfgStruct->ADC_SampChn-6)*5);
		ADC->SMPR1 = tp1|tp2;
	}
	if(ADC_SampChnCfgStruct->ADC_SampChnACCCmd!= DISABLE)
	{	
		ADC->CR3 &=~ADC_CR3_ACCLENGTHMask;
		ADC->CR3 |=((ADC_SampChnCfgStruct->ADC_SampChnACCLength-1)<<16);
	}	
}



/**
  * @brief  Enables or disables the ADC scanning mode .
  * @param  NewState: new state of the ADC scanning mode.
  *         This parameter can be: ENABLE or DISABLE.
  * @retval None
  */
void ADC_ScanModeCmd(FunctionalState NewState)
{
	/* Check the parameters */
	assert_param(IS_FUNCTIONAL_STATE(NewState));
	
  if (NewState != DISABLE)
  {   
    ADC->CR0 |= ADC_CR0_SCAN;
  }
  else
  {
    ADC->CR0 &= ~ADC_CR0_SCAN;
  }
}

/**
  * @brief  Enables or disables the ADC Continue mode .
  * @param  NewState: new state of the ADC Continue mode.
  *         This parameter can be: ENABLE or DISABLE.
  * @retval None
  */
void ADC_ContinueModeCmd(FunctionalState NewState)
{
	/* Check the parameters */
	assert_param(IS_FUNCTIONAL_STATE(NewState));
	
  if (NewState != DISABLE)
  {   
    ADC->CR0 |= ADC_CR0_CONT;
  }
  else
  {
    ADC->CR0 &= ~ADC_CR0_CONT;
  }
}

/**
 * @brief  Enables or disables the ADC DMA.
 * @param  NewState: new state of the ADC DMA.
 *         This parameter can be: ENABLE or DISABLE.
 * @retval None
 */
void ADC_DMACmd(FunctionalState NewState) {
  assert_param(IS_FUNCTIONAL_STATE(NewState));

  if (NewState != DISABLE) {
    ADC->CR0 |= ADC_CR0_DMA;
  } else {
    ADC->CR0 &= ~ADC_CR0_DMA;
  }
}

/**
  * @brief  Enables or disables the ADC Automatic injection mode .
  * @param  NewState: new state of the ADC Automatic injection mode.
  *         This parameter can be: ENABLE or DISABLE.
  * @retval None
  */
void ADC_JAutoModeCmd(FunctionalState NewState)
{
	/* Check the parameters */
	assert_param(IS_FUNCTIONAL_STATE(NewState));
	
  if (NewState != DISABLE)
  {   
    ADC->CR0 |= ADC_CR0_JAUTO;
  }
  else
  {
    ADC->CR0 &= ~ADC_CR0_JAUTO;
  }
}

/**
  * @brief  Configures the Regular-channel Sampling sequence.
  * @param  SEQUn:ADC converter index
  * @param  ADC_Chn:Sampling channel 
  * @retval None
  */
void ADC_SQRnChnConfig(unsigned int SEQUn,unsigned int  ADC_Chn)
{
	/* Check the parameters */
	assert_param(IS_ADC_CHNSRC(ADC_Chn));
	assert_param(IS_ADC_SEQUSRC(SEQUn));
	
	if(SEQUn<8)
	{
		ADC->SQR2 &=~(0xf<<(SEQUn<<2));
		ADC->SQR2 |=(ADC_Chn<<(SEQUn<<2));
	}
  else
	{
	  ADC->SQR1 &=~(0xf<<((SEQUn-8)<<2));
		ADC->SQR1 |=(ADC_Chn<<((SEQUn-8)<<2));
	}
}

/**
  * @brief  Configures the Inject-channel Sampling sequence.
  * @param  SEQUn:ADC converter index
  * @param  ADC_Chn:Sampling channel 
  * @retval None
  */
void ADC_JSQRnChnConfig(unsigned int SEQUn,unsigned int  ADC_Chn)
{
	/* Check the parameters */
	assert_param(IS_ADC_CHNSRC(ADC_Chn));
	assert_param(IS_ADC_JSEQUSRC(SEQUn));
	
	ADC->JSQR &=~(0xf<<(SEQUn<<2));
	ADC->JSQR |=(ADC_Chn<<(SEQUn<<2));
}

/**
  * @brief  Configures the Regular-channel converter Length.
  * @param  SqrLength:ADC converter Length
  * @retval None
  */
void ADC_SQRLengthConfig(unsigned int SqrLength)
{
	/* Check the parameters */
	assert_param(IS_ADC_SQRLENGTH(SqrLength));
	
	ADC->SQR1 &=~ADC_SQR_SQRLENGTHMask;
	ADC->SQR1 |= (uint32_t)((SqrLength-1)<<28);
}

/**
  * @brief  Configures the Inject-channel converter Length.
  * @param  JSqrLength:ADC converter Length
  * @retval None
  */
void ADC_JSQRLengthConfig(unsigned int JSqrLength)
{
	/* Check the parameters */
	assert_param(IS_ADC_JSQRLENGTH(JSqrLength));
	
	ADC->JSQR &=~ADC_JSQR_JSQRLENGTHMask; 
	ADC->JSQR |=(unsigned int)((JSqrLength-1)<<30);
}


/**
  * @brief  Configures the high and low thresholds of the analog watchdog.
  * @param  ADCWdgThresholdStruct: pointer to an ADCWdgThreshold_Typedef structure 
  *         that contains the ADC Watchdog Threshold configuration 
  * @retval None
  */
void ADC_WatchdogThresholdConfig(ADCWdgThreshold_Typedef* ADCWdgThresholdStruct)
{
  /* Check the parameters */
	assert_param(IS_FUNCTIONAL_STATE(NewState));
	assert_param(IS_ADC_CONVGROUP(ADCThresholdStruct->ADC_ConvGroup));
	assert_param(IS_ADC_HIGHTHRESHOLD(ADCThresholdStruct->ADC_Threshold_High));
	assert_param(IS_ADC_LOWTHRESHOLD(ADCThresholdStruct->ADC_Threshold_Low));
	
	if(ADCWdgThresholdStruct->ADC_ConvGroup==ADC_ConvGroup_Regular)
	{
		ADC->THR = (ADCWdgThresholdStruct->ADC_WdgThreshold_High<<16)+ADCWdgThresholdStruct->ADC_WdgThreshold_Low;
	}
	else
	{
	  ADC->JTHR = (ADCWdgThresholdStruct->ADC_WdgThreshold_High<<16)+ADCWdgThresholdStruct->ADC_WdgThreshold_Low;
	}
}

/**
  * @brief  Configures ADC converter External Trigger.
  * @param  ADC_ExtTrgInitStruct: pointer to an ADC_ExtTrgInitTypeDef structure 
  *         that contains the ADC External Trigger configuration 
  * @retval None
  */
void ADC_ExtTriggerConfig(ADC_ExtTrgInitTypeDef* ADC_ExtTrgInitStruct)
{
	unsigned int tp1;
	/* Check the parameters */
	assert_param(IS_ADC_CONVGROUP(ADC_ExtTrgInitStruct->ADC_ConvGroup));
	assert_param(IS_ADC_EXTTRGSRC(ADC_ExtTrgInitStruct->ADC_ExtTrgSrc));
	assert_param(IS_ADC_EXTTRGEDGE(ADC_ExtTrgInitStruct->ADC_ExtTrgEdge));
	
	if(ADC_ExtTrgInitStruct->ADC_ConvGroup == ADC_ConvGroup_Regular)
	{
		tp1  =  ADC->CR1;
		tp1 &= ~(ADC_CR12_EXTTRGEDGEMask|ADC_CR12_EXTTRGSRCMask);
		tp1 |= (ADC_ExtTrgInitStruct->ADC_ExtTrgEdge<<30)|(ADC_ExtTrgInitStruct->ADC_ExtTrgSrc<<12);
		ADC->CR1 = tp1;	  
	}
	else		
  {
		tp1  =  ADC->CR2;
		tp1 &= ~(ADC_CR12_EXTTRGEDGEMask|ADC_CR12_EXTTRGSRCMask);
		tp1 |= (ADC_ExtTrgInitStruct->ADC_ExtTrgEdge<<30)|(ADC_ExtTrgInitStruct->ADC_ExtTrgSrc<<12);
		ADC->CR2 = tp1;	  
	}
}

/**
  * @brief  Configures ADC Discontinue converter settings.
  * @param  ADC_DiscCfgStruct: pointer to an ADC_DiscontinueCfgTypeDef structure 
  *         that contains the ADC Discontinue converter settings 
  * @retval None
  */
void ADC_DiscontinueConfig(ADC_DiscontinueCfgTypeDef* ADC_DiscCfgStruct)
{
	unsigned int tp1;
	/* Check the parameters */
	assert_param(IS_ADC_CONVGROUP(ADC_DiscCfgStruct->ADC_ConvGroup));
	assert_param(IS_FUNCTIONAL_STATE(ADC_DiscCfgStruct->ADC_DiscConvMode));
	
	if(ADC_DiscCfgStruct->ADC_ConvGroup==ADC_ConvGroup_Regular)
	{	
		assert_param(IS_ADC_DISCCONVLENGTH_REG(ADC_DiscCfgStruct->ADC_DiscConvLength));
    if(ADC_DiscCfgStruct->ADC_DiscConvModeCmd != DISABLE)
		{
			ADC->CR1 |=  (ADC_DiscCfgStruct->ADC_DiscConvModeCmd<<8);
		}
		else
		{
			ADC->CR1 &= ~(ADC_DiscCfgStruct->ADC_DiscConvModeCmd<<8);
		}
	}
  else
	{	
    assert_param(IS_ADC_DISCCONVLENGTH_INJ(ADC_DiscCfgStruct->ADC_DiscConvLength));		
    if(ADC_DiscCfgStruct->ADC_DiscConvModeCmd != DISABLE)
		{
			ADC->CR2 |= (ADC_DiscCfgStruct->ADC_DiscConvModeCmd<<8);
		}
		else
		{
			ADC->CR2 &= ~(ADC_DiscCfgStruct->ADC_DiscConvModeCmd<<8);
		}
	}
	
	tp1  = ADC->CR3;
	tp1 &= ~ADC_CR3_DISCNUMMask;
	ADC->CR3 = tp1|ADC_DiscCfgStruct->ADC_DiscConvLength;
}

/**
  * @brief  Power on and down of the ADC
  * @param  NewState: new state of the ADC Power.
  *          This parameter can be: ENABLE or DISABLE.
  * @retval None
  */
void ADC_PowerOnCmd(FunctionalState NewState)
{
	/* Check the parameters */
	assert_param(IS_FUNCTIONAL_STATE(NewState));
	
	if(NewState!= DISABLE)
	  ADC->CR0 |= ADC_CR0_POWERON;
	else
		ADC->CR0 &=~ADC_CR0_POWERON;
}


/**
  * @brief  Enables or disables the ADC Software-Start .
  * @param  NewState: new state of the ADC Software-Start.
  *         This parameter can be: ENABLE or DISABLE.
  * @retval None
  */
void ADC_SWStartCmd(ADCConvGroup_Typedef convgroup,FunctionalState NewState)
{
  /* Check the parameters */
	assert_param(IS_FUNCTIONAL_STATE(NewState));
	assert_param(IS_ADC_CONVGROUP(convgroup));
	
	if(convgroup==ADC_ConvGroup_Regular)
	{
	  if(NewState!= DISABLE)
	  	ADC->CR1 |= ADC_CR12_SWSTART;
		else
			ADC->CR1 &=~ADC_CR12_SWSTART;
	}
  else
	{
	  if(NewState!= DISABLE)
	  	ADC->CR2 |= ADC_CR12_SWSTART;
		else
			ADC->CR2 &=~ADC_CR12_SWSTART;
	}
}

/**
  * @brief  Get the ADC converter Date.
  * @param  ADC_ConvData: Specify the data to be fetched
  *          This parameter can be one of the following values:
  *            @arg ADC_ConvData_InJect1: InJect Channle1 converter Date 
  *            @arg ADC_ConvData_InJect2: InJect Channle2 converter Date 
  *            @arg ADC_ConvData_InJect3: InJect Channle3 converter Date  
  *            @arg ADC_ConvData_InJect4: InJect Channle4 converter Date 
  *            @arg ADC_ConvData_Regular: Regular Channle converter Date
  *            @arg ADC_ConvData_ACC:  converter ACC Date
  * @retval the ADC counter value
  */
unsigned int ADC_GetData(unsigned int  ADC_ConvData) 
{
	unsigned int tp1;
	/* Check the parameters */
	assert_param(IS_ADC_CONVDATA(ADC_ConvData)); 
	
	if(ADC_ConvData==ADC_ConvData_InJect1)
		tp1 = ADC->JDR1;
	
	else if(ADC_ConvData==ADC_ConvData_InJect2)
		tp1 = ADC->JDR2;
	
	else if(ADC_ConvData==ADC_ConvData_InJect3)
		tp1 = ADC->JDR3;
	
	else if(ADC_ConvData==ADC_ConvData_InJect4)
		tp1 = ADC->JDR4;
	
	else if(ADC_ConvData==ADC_ConvData_Regular)
		tp1 = ADC->DR;
	
	else if(ADC_ConvData==ADC_ConvData_ACC)
    tp1 =	ADC->ACCDR;
	
  return tp1;
}

/**
 * @brief  Get the ADC converter Conversion value.
 * @param  ADC_ConvData: Specify the data to be fetched
 * @retval the ADC counter value
 */
unsigned int ADC_GetConversionValue(unsigned int ADC_ConvData) {
  assert_param(IS_ADC_CONVDATA(ADC_ConvData));

  if (ADC_ConvData == ADC_ConvData_InJect1) {
    return ADC->JDR1 & 0x0FFF;
  } else if (ADC_ConvData == ADC_ConvData_InJect2) {
    return ADC->JDR2 & 0x0FFF;
  } else if (ADC_ConvData == ADC_ConvData_InJect3) {
    return ADC->JDR3 & 0x0FFF;
  } else if (ADC_ConvData == ADC_ConvData_InJect4) {
    return ADC->JDR4 & 0x0FFF;
  } else if (ADC_ConvData == ADC_ConvData_Regular) {
    return ADC->DR & 0x0FFF;
  } else if (ADC_ConvData == ADC_ConvData_ACC) {
    return ADC->ACCDR & 0x000FFFFF;
  } else {
    return 0;
  }
}

/**
  * @}
  */ 


/** @defgroup 	ADC_InteFlag Interrupts and flags management functions
 *  @brief   	Interrupts and flags management functions
 *
@verbatim   
 ===============================================================================
           #####  Interrupts and flags management functions #####
 ===============================================================================  
@endverbatim
  * @{
  */
/**
  * @brief  Enables or disables the ADC interrupts.
  * @param  ADC_IT: specifies the flag to check.
  *          This parameter can be one of the following values:
  *            @arg ADC_JSQRAWD:  Inject Regular Channle Analog Watchdog interrupt flag
  *            @arg ADC_SQRAWD:  Regular Channle Analog Watchdog interrupt flag
  *            @arg ADC_JEOC:  Inject Channle End of converter interrupt flag
  *            @arg ADC_EOC:  Regular Channle End of converter interrupt flag
	*            @arg ADC_ACC:  ACC status interrupt flag
  *            @arg ADC_OVF:  Overflow status interrupt flag
  *            @arg ADC_VLD:  The data valid interrupt flag
  * @param  NewState: new state of the ADC interrupt status.
  *         This parameter can be: ENABLE or DISABLE.
  * @retval None
  */
void ADC_ITConfig(unsigned int ADC_IT, FunctionalState NewState)
{
	/* Check the parameters */
	assert_param(IS_ADC_IT(ADC_IT)); 
	assert_param(IS_FUNCTIONAL_STATE(NewState));
	
	if (NewState != DISABLE)
	{
		ADC->CR6 |= ADC_IT;
	}
	else
	{
		ADC->CR6 &= ~ADC_IT;
	}
}


/**
  * @brief  Checks whether the ADC interrupt flag is set or not.
  * @param  ADC_IT: specifies the flag to check.
  *          This parameter can be one of the following values:
  *            @arg ADC_JSQRAWD:  Inject Regular Channle Analog Watchdog interrupt flag
  *            @arg ADC_SQRAWD:  Regular Channle Analog Watchdog interrupt flag
  *            @arg ADC_JEOC:  Inject Channle End of converter interrupt flag
  *            @arg ADC_EOC:  Regular Channle End of converter interrupt flag
	*            @arg ADC_ACC:  ACC status interrupt flag
  *            @arg ADC_OVF:  Overflow status interrupt flag
  *            @arg ADC_VLD:  The data valid interrupt flag
  * @retval The new state of ADC_IT (SET or RESET).
  */
ITStatus ADC_GetIT(unsigned int ADC_IT)
{
	/* Check the parameters */
	assert_param(IS_ADC_IT(ADC_IT)); 
	
	return ( (ADC->INTSR& ADC_IT) == ADC_IT ) ?  SET : RESET;
}



/**
  * @brief  Clears the ADCx's status and interrupt flags.
  * @param  ADC_IT: specifies the ADC interrupt pending bit to clear.
  *          This parameter can be one of the following values:
  *            @arg ADC_JSQRAWD:  Inject Regular Channle Analog Watchdog  flag
  *            @arg ADC_SQRAWD:  Regular Channle Analog Watchdog  flag
  *            @arg ADC_JEOC:  Inject Channle End of converter  flag
  *            @arg ADC_EOC:  Regular Channle End of converter  flag
	*            @arg ADC_ACC:  ACC status  flag
  *            @arg ADC_OVF:  Overflow status  flag
  *            @arg ADC_VLD:  The data valid  flag                    
  * @retval None
  */
void ADC_ClearIT(unsigned int ADC_IT)
{
	/* Check the parameters */
	assert_param(IS_ADC_IT(ADC_IT)); 
	
  ADC->CLRSR = ADC_IT;
}

/**
  * @brief  Checks whether the ADC Status flag is set or not.
  * @param  ADC_Flag: specifies the flag to check.
  *          This parameter can be one of the following values:
  *            @arg ADC_JSQRAWD:  Inject Regular Channle Analog Watchdog Status flag
  *            @arg ADC_SQRAWD:  Regular Channle Analog Watchdog Status flag
  *            @arg ADC_JEOC:  Inject Channle End of converter Status flag
  *            @arg ADC_EOC:  Regular Channle End of converter Status flag
  *            @arg ADC_JSTART: Inject Channle converter has started Status flag
  *            @arg ADC_START:  Regular Channle converter has started Status flag
	*            @arg ADC_ACC:  ACC status Status flag
  *            @arg ADC_OVF:  Overflow status Status flag
  *            @arg ADC_VLD:  The data valid Status flag
  * @retval The new state of ADC_Flag (SET or RESET).
  */
FlagStatus ADC_GetFlagStatus(unsigned int ADC_Flag)
{
	/* Check the parameters */
	assert_param(IS_ADC_STS(ADC_Flag)); 
	
	return ( (ADC->SR & ADC_Flag) == ADC_Flag )?  SET : RESET;
}	


/**
  * @brief  Clears the ADCx's status and interrupt flags.
  * @param  ADC_IT: specifies the ADC interrupt pending bit to clear.
  *          This parameter can be one of the following values:
  *            @arg ADC_JSQRAWD:  Inject Regular Channle Analog Watchdog  flag
  *            @arg ADC_SQRAWD:  Regular Channle Analog Watchdog  flag
  *            @arg ADC_JEOC:  Inject Channle End of converter  flag
  *            @arg ADC_EOC:  Regular Channle End of converter  flag
	*            @arg ADC_ACC:  ACC status  flag
  *            @arg ADC_OVF:  Overflow status  flag
  *            @arg ADC_VLD:  The data valid  flag                    
  * @retval None
  */
void ADC_ClearSR(unsigned int ADC_FLAG)
{
	/* Check the parameters */
	assert_param(IS_ADC_STS(ADC_FLAG)); 
	
  ADC->CLRSR = ADC_FLAG;
}
/**
  * @}
  */ 

/**
  * @}
  */

/**
  * @}
  */ 

/**
  * @} 
  */ 

/************************ (C) COPYRIGHT Giantec Semicondutor Inc *****END OF FILE****/
